/****************************************************************************
	This file is part of Basqet.

	Basqet is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Basqet is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
    along with Basqet.  If not, see <http://www.gnu.org/licenses/>.

****************************************************************************/


#include "filedialog.h"

#include <QFileDialog>

#include <QtDebug>

FileDialog::FileDialog()
{
}


QString FileDialog::getSaveFileName(QWidget* parent,
									QString title,
									QString path,
									QString	filters,
									QString* selectedFilter /* = 0 */)
{
	QString	fileName;


#ifdef Q_OS_LINUX

	QFileDialog             fileDialog(parent, title);

	fileDialog.setNameFilter(filters);
	fileDialog.setAcceptMode(QFileDialog::AcceptSave);

	if (!path.isEmpty())
			fileDialog.setDirectory(path);

	if (fileDialog.exec())
	{
			fileName = fileDialog.selectedFiles().first();
			if (selectedFilter)
			{
				*selectedFilter = fileDialog.selectedFilter();
			}

	}





#else

	fileName = QFileDialog::getSaveFileName(parent,
											title,
											path,
											filters,
											selectedFilter
											);

	if (selectedFilter)
	{
		qDebug() << "Selected Filter is:" << *selectedFilter;
	}

#endif

	return fileName;

}


QString FileDialog::getExistingDirectory(QWidget* parent,
										 QString title,
										 QString path)
{
	QString	fileName;

#ifdef Q_OS_LINUX

	QFileDialog		fileDialog(parent, title);

	fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
	fileDialog.setFileMode(QFileDialog::Directory);
	fileDialog.setOption(QFileDialog::ShowDirsOnly, true);

	if (!path.isEmpty())
			fileDialog.setDirectory(path);

	if (fileDialog.exec())
	{
		fileName = fileDialog.selectedFiles().first();
	}


#else

	fileName = QFileDialog::getExistingDirectory(parent,
											title,
											path);


#endif

	return fileName;

}
